package com.smedi.ismedi.file.feign;

import com.smedi.ismedi.file.dto.request.SignatureRequest;
import com.smedi.ismedi.file.dto.response.FileInfoResponse;
import com.smedi.ismedi.web.starter.common.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotNull;
import java.io.File;
import java.io.IOException;
import java.util.List;

/**
 * @Author Jimmy
 * @Date 2021/6/3 17:11
 */
@FeignClient(name = "ismedi-file")
@Api(value = "文件管理", tags = {"文件管理"})
@RequestMapping(value = "file")
@RestController
public interface RemoteFileFeignApi {

    /**
     * 文件上传
     *
     * @param file
     * @return
     */
    @ApiOperation(value = "文件上传", nickname = "文件上传", httpMethod = "POST", response = ResponseData.class)
    @PostMapping(value = "/uploadFile", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    ResponseData<FileInfoResponse> fileUpLoad(@ApiParam(value = "file", required = true) @RequestPart(value = "file", required = true) MultipartFile file);

    /**
     * 上传File格式的文件
     *
     * @param file 文件
     * @return ResponseData<FileInfoResponse>
     */
    @ApiOperation(value = "上传File格式的文件", nickname = "上传File格式的文件", httpMethod = "POST", response = ResponseData.class)
    @PostMapping(value = "/uploadFileInFile")
    ResponseData<FileInfoResponse> fileUpLoadInFile(@ApiParam(value = "file", required = true) @RequestPart(value = "file") File file);

    /**
     * 上传文件确认
     *
     * @param signKey
     * @return
     */
    @ApiOperation(value = "上传文件确认", nickname = "上传文件确认", response = ResponseData.class)
    @GetMapping(value = "/uploadFileConfirm")
    ResponseData<Boolean> uploadFileConfirm(@ApiParam(value = "signKey", required = true) @RequestParam(value = "signKey", required = true) String signKey);

    /**
     * 获取文件信息
     *
     * @param signKey
     * @return
     */
    @ApiOperation(value = "获取文件信息", nickname = "获取文件信息", response = ResponseData.class)
    @GetMapping(value = "/getFileInfoBySignKey")
    ResponseData<FileInfoResponse> getFileInfo(@ApiParam(value = "signKey", required = true) @RequestParam(value = "signKey", required = true) String signKey);

    /**
     * 获取文件信息
     *
     * @param signKeys
     * @return
     */
    @ApiOperation(value = "获取文件信息", nickname = "获取文件信息", response = ResponseData.class)
    @GetMapping(value = "/getFileInfosBySignKeys")
    ResponseData<List<FileInfoResponse>> getFileList(@ApiParam(value = "signKeys", required = true) @RequestParam(value = "signKeys", required = true) List<String> signKeys);

    /**
     * 获取文件信息
     *
     * @param signKeys
     * @return
     */
    @ApiOperation(value = "获取文件信息", nickname = "获取文件信息", response = ResponseData.class)
    @PostMapping(value = "/getFileInfosBySignKeys")
    ResponseData<List<FileInfoResponse>> getFileListByPost(@ApiParam(value = "signKeys", required = true) @RequestBody List<String> signKeys);

    /**
     * 删除文件
     *
     * @param signKey
     * @param reason
     * @return
     */
    @ApiOperation(value = "删除文件", nickname = "删除文件", response = ResponseData.class)
    @DeleteMapping(value = "/delete")
    ResponseData<Boolean> deleteFileBySignKey(@NotNull @ApiParam(value = "signKey", required = true)
                                              @RequestParam(value = "signKey", required = true) String signKey,
                                              @NotNull @ApiParam(value = "删除原因", required = true)
                                              @RequestParam(value = "reason", required = true) String reason);

    /**
     * 根据下载密钥下载文件
     *
     * @param signKey
     * @return
     */
    @ApiOperation(value = "根据下载密钥下载文件", nickname = "根据下载密钥下载文件", response = ResponseData.class)
    @GetMapping(value = "/downloadFileBySignKey")
    ResponseData<Boolean> downloadFileBySignKey(@NotNull @ApiParam(value = "signKey", required = true)
                                                @RequestParam(value = "signKey", required = true) String signKey, HttpServletResponse response);


    /**
     * 根据下载密钥下载文件
     *
     * @param signKey
     * @return
     */
    @ApiOperation(value = "根据下载密钥下载文件", nickname = "根据下载密钥下载文件", response = ResponseData.class)
    @GetMapping(value = "/downloadFileBySignKey/byte")
    ResponseData<byte[]> downloadFileBySignKey(@NotNull @ApiParam(value = "signKey", required = true)
                                                @RequestParam(value = "signKey", required = true) String signKey) throws IOException;

    /**
     * 下载文件
     *
     * @param group
     * @param path
     * @param fileName
     * @return
     */
    @ApiIgnore
    @ApiOperation(value = "下载文件", nickname = "下载文件", response = ResponseData.class)
    @GetMapping(value = "/download")
    ResponseData<Boolean> downloadFile(@NotNull @ApiParam(value = "group", required = true)
                                       @RequestParam(value = "group", required = true) String group,
                                       @NotNull @ApiParam(value = "path", required = true)
                                       @RequestParam(value = "path", required = true) String path,
                                       @NotNull @ApiParam(value = "fileName", required = true)
                                       @RequestParam(value = "fileName", required = true) String fileName, HttpServletResponse response);

    /**
     * 下载文件
     *
     * @param group
     * @param path
     * @param fileName
     * @return
     */
    @ApiIgnore
    @ApiOperation(value = "下载文件", nickname = "下载文件", response = ResponseData.class)
    @GetMapping(value = "/download/byte")
    ResponseData<byte[]> downloadFile(@NotNull @ApiParam(value = "group", required = true)
                                       @RequestParam(value = "group", required = true) String group,
                                       @NotNull @ApiParam(value = "path", required = true)
                                       @RequestParam(value = "path", required = true) String path,
                                       @NotNull @ApiParam(value = "fileName", required = true)
                                       @RequestParam(value = "fileName", required = true) String fileName) throws IOException;

    /**
     * 文件入参的文件转换
     *
     * @param file 需要转换的文件
     * @return ResponseData<FileInfoResponse>
     */
    @ApiOperation(value = "文件入参的文件转换", nickname = "文件入参的文件转换", httpMethod = "POST", response = ResponseData.class)
    @PostMapping(value = "/convertFileToPdfByFile", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    ResponseData<FileInfoResponse> postConvertFileToPdfWithFile(@ApiParam(value = "file", required = true) @RequestPart(value = "file") MultipartFile file) ;

    /**
     * key入参的文件转换
     *
     * @param fileKey 文件Key
     * @return ResponseData<FileInfoResponse>
     */
    @ApiOperation(value = "key入参的文件转换", nickname = "key入参的文件转换", httpMethod = "POST", response = ResponseData.class)
    @PostMapping(value = "/convertFileToPdfByFileKey")
    ResponseData<FileInfoResponse> postConvertFileToPdfWithFileKey(@NotNull @ApiParam(value = "String", required = true) @RequestParam(value = "fileKey") String fileKey);

    /**
     * 文件入参的文件转换(不支持签章)
     *
     * @param file 需要转换的文件
     * @return ResponseData<FileInfoResponse>
     */
    @ApiOperation(value = "文件入参的文件转换", nickname = "文件入参的文件转换", httpMethod = "POST", response = ResponseData.class)
    @PostMapping(value = "/convertFileToPdfByFileNoSign", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    ResponseData<FileInfoResponse> postConvertFileToPdfWithFileNoSign(@ApiParam(value = "file", required = true) @RequestPart(value = "file") MultipartFile file) ;

    /**
     * key入参的文件转换(不支持签章)
     *
     * @param fileKey 文件Key
     * @return ResponseData<FileInfoResponse>
     */
    @ApiOperation(value = "key入参的文件转换", nickname = "key入参的文件转换", httpMethod = "POST", response = ResponseData.class)
    @PostMapping(value = "/convertFileToPdfByFileKeyNoSign")
    ResponseData<FileInfoResponse> postConvertFileToPdfWithFileKeyNoSign(@NotNull @ApiParam(value = "String", required = true) @RequestParam(value = "fileKey") String fileKey) ;

    /**
     * 签章
     *
     * @param signatureRequests 签章请求
     * @return ResponseData<FileInfoResponse>
     */
    @ApiOperation(value = "签章", nickname = "签章", httpMethod = "POST", response = ResponseData.class)
    @PostMapping(value = "/Signatures")
    ResponseData<FileInfoResponse> postSignatures(@Validated @RequestBody List<SignatureRequest> signatureRequests);

    /**
     * 文件入参的文件转换(不支持签章)
     *·1·
     * @param file 需要转换的文件
     * @return ResponseData<FileInfoResponse>
     */
    @ApiOperation(value = "文件入参的文件转换", nickname = "文件入参的文件转换", httpMethod = "POST", response = ResponseData.class)
    @PostMapping(value = "/convertFileToPdfByFileNoFree", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    ResponseData<FileInfoResponse> postConvertFileToPdfWithFileNoFree(@ApiParam(value = "file", required = true) @RequestPart(value = "file") MultipartFile file) ;

    /**
     * key入参的文件转换(收费)
     *
     * @param fileKey 文件Key
     * @return ResponseData<FileInfoResponse>
     */
    @ApiOperation(value = "key入参的文件转换", nickname = "key入参的文件转换", httpMethod = "POST", response = ResponseData.class)
    @PostMapping(value = "/convertFileToPdfByFileKeyNoFree")
    ResponseData<FileInfoResponse> postConvertFileToPdfWithFileKeyNoFree(@NotNull @ApiParam(value = "String", required = true) @RequestParam(value = "fileKey") String fileKey) ;

    /**
     * 压缩文件
     *
     * @param fileKeys 文件Keys
     * @return ResponseData<FileInfoResponse>
     */
    @ApiOperation(value = "key入参的文件转换", nickname = "key入参的文件转换", httpMethod = "POST", response = ResponseData.class)
    @PostMapping(value = "/postZipBySignKeys")
    ResponseData<FileInfoResponse> postZipBySignKeys(@NotNull @ApiParam(value = "List", required = true) @RequestParam(value = "fileKeys") List<String> fileKeys) throws IOException;

    @ApiOperation(value = "多pdf合并",nickname = "多pdf合并",httpMethod = "POST")
    @PostMapping(value = "/pdf/merge")
    ResponseData<FileInfoResponse> pdfMerge(@RequestBody List<String> signKeys) throws IOException;
}
